package com.zodiac.app.szse.e.e0201.e020101;

import com.github.lzm320a99981e.component.dataautomation.Processors;
import com.github.lzm320a99981e.component.dataautomation.Transfer;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.Objects;

@Processors(E020101Processor.class)
@Component
public class E020101Transfer implements Transfer<List<E020101Model>> {
    @Autowired
    private MongoTemplate mongoTemplate;

    @Override
    public void transfer(List<E020101Model> models) {
        if (Objects.isNull(models) || models.isEmpty()) {
            return;
        }
        Class<? extends E020101Model> cls = models.get(0).getClass();
        mongoTemplate.dropCollection(cls);
        mongoTemplate.insert(models, cls);
    }
}
